package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.RecordMapper;
import com.itheima.domain.Record;
import com.itheima.domain.User;
import com.itheima.entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.itheima.service.RecordService;
@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;
    @Override
    public Integer addrecond(Record recond) {
        return recordMapper.addrecond(recond);
    }

    @Override
    public PageResult searchrecond(Record recond, User user, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        if(!"ADMIN".equals(user.getRole())){
            recond.setBookborrower(user.getName());
        }
        Page<Record> page1= recordMapper.searchrecond(recond);
        return new PageResult(page1.getTotal(),page1.getResult());
    }
}
